package com.stylefeng.guns.core.util.excel.demo;

import com.stylefeng.guns.core.util.excel.demo.analyze.DemoExcelAnalyze;
import com.stylefeng.guns.core.util.excel.demo.export.DemoExcelExport;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class DemoExcelBoRun {

    public static void main(String[] args) throws Exception {

        /**
         * 导出案例
         */
        List<DemoExcelBo> list = new ArrayList<DemoExcelBo>();
        DemoExcelBo bo = new DemoExcelBo();
        {
            bo.setId("001");
            bo.setName("张凯");
        }
        DemoExcelBo bo1 = new DemoExcelBo();
        {
            bo1.setId("002");
            bo1.setName("刘亚洲");
        }
        DemoExcelBo bo2 = new DemoExcelBo();
        {
            bo2.setId("003");
            bo2.setName("吴帮权");
        }
        DemoExcelBo bo3 = new DemoExcelBo();
        {
            bo2.setId("004");
            bo2.setName("张国瑞");
        }
        list.add(bo);
        list.add(bo1);
        list.add(bo2);
        list.add(bo3);
        HSSFWorkbook workbook = new DemoExcelExport().buildExportExcel(list);
        FileOutputStream out = new FileOutputStream("/Users/carloszhang/Downloads/export.xls");
        workbook.write(out);
        out.close();

        /**
         * 导入案例
         */
        InputStream is = new FileInputStream("/Users/carloszhang/Downloads/test.xls");
        List<DemoExcelBo> datas = new DemoExcelAnalyze().analyzeExcel(is);
        datas.forEach(data -> {
            System.out.println(data);
        });

    }
}
